package com.taofuxn.yycreazy.mvp.presenter;

import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.taofuxn.yycreazy.mvp.BasePresenter;
import com.taofuxn.yycreazy.mvp.model.ZhuangbiBean;
import com.taofuxn.yycreazy.mvp.view.IZhuangbiView;
import com.taofuxn.yycreazy.retrofit.ApiClient;
import com.taofuxn.yycreazy.retrofit.ApiStore;
import com.taofuxn.yycreazy.rxjava.ApiCallback;
import com.taofuxn.yycreazy.rxjava.SubscriberCallback;
import com.taofuxn.yycreazy.ui.activity.ZhuangbiActivity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by taofuxn on 2016/9/21.
 */
public class ZhuangbiPresenter extends BasePresenter {
    private IZhuangbiView mIZhuangbiView;

    public ZhuangbiPresenter(IZhuangbiView mIZhuangbiView) {
        this.mIZhuangbiView = mIZhuangbiView;
        onAttachView(mIZhuangbiView);
    }


    public void getZhuangbiList(String key) {
        if (TextUtils.isEmpty(key))
            key = "装逼";
        addSubscription(  mRetrofit.create(ApiStore.class).searchZhuangbiList("http://zhuangbi.info/search", key),new SubscriberCallback(new ApiCallback<ArrayList<ZhuangbiBean>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onFailed(int code, String msg) {
                mIZhuangbiView.dismissLoading();
            }

            @Override
            public void onSuccess(ArrayList<ZhuangbiBean> mDatas) {
                mIZhuangbiView.requestSuccess(mDatas);
                mIZhuangbiView.dismissLoading();
            }
        }));

    }



}
